<template>
	<vue-office-docx
		ref="vueOffice"
		:src="url"
		style="height: 100%"
		@rendered="rendered"
		@error="error" />
</template>

<script>
	import VueOfficeDocx from '@vue-office/docx';
	import '@vue-office/excel/lib/index.css';
	import { downFile } from '@/api/system/oss';
	export default {
		props: {
			src: {
				required: true,
			},
		},
		components: { VueOfficeDocx },
		data() {
			return {
				url: '',
			};
		},
		created() {
			this.downFile();
		},
		methods: {
			downFile() {
				if (this.src) {
					downFile(this.src)
						.then(res => {
							if (res) {
								this.url = URL.createObjectURL(res);
							} else {
								throw new Error();
							}
						})
						.catch(() => {
							this.error();
						});
				}
			},
			rendered() {
				this.$emit('rendered');
			},
			error(err) {
				this.$emit('error');
			},
		},
	};
</script>

<style lang="scss" scoped></style>
